package com.knightboy.smartshoes.core;

public class LisStepUtil {

	private static double limit = -8.49;
	private static final int COUNT = 3;                          //�ж�б����������
    private static double[] datas = new double[COUNT];     //�洢����ݵ�����
    private static long[] times = new long[COUNT]; //�洢��ʱ�������
    private static int position1 = 0;     //  ����������±�
    //private static int position2=0;//ʱ���������±�
    private static int flag1 = 0; //��־�Ƿ�����������Ƿ����3��ֵ
    private static int flag2=0;//��� �Ƿ��ǵ�һ�η�ֵ��
    private static int flag3=0;//�Ƿ��ڿ��ԼƲ���״̬��
   // private static long[] temptime=new long[2];//���������ʱ���ʱ��
    private static long temptime=0;

	public static double getLimit() {
		return limit;
	}

	public static void setLimit(double limit) {
		LisStepUtil.limit = limit;
	}

	public static boolean isCount(double variable,long time){
    	if (flag1==0&&position1!=3){   //���Ǹտ�ʼ��û����3��ֵ����һֱ������Ϊֹ
    		datas[position1] = variable;
    		times[position1]=time;
             position1++;
             return false;}
    	else{  flag1=1;
    	      if(position1==3)
    		position1=position1%3;
    	      if((flag3==1&&times[(position1+2)%3]-temptime<=2000)||flag2==0)
    	      {
    	     if(datas[(position1+1)%3]-datas[position1]<=0&&datas[(position1+2)%3]-datas[(position1+1)%3]>=0){//�ж��Ƿ��Ǽ�Сֵ��
    	    	 if(datas[(position1+1)%3]<= limit)//  �Ƿ�С��-8.49 �Ʋ���ֵ��PS.����ļ��ٶȶ��ǳ���g�ģ�
    	    		 { if(flag2==0){                      //���ж��ǲ��ǵ�һ�η�ֵ����Ϊ��һ����ֱ�ӼƲ�������ʱ���������temptime��
    	    			 temptime=times[(position1+1)%3];
    	    			
    	    			 flag2=1;
    	    			 flag3=1;
    	    			 datas[position1] = variable;
    	    			 times[position1]=time;
    	                 position1++;
    	    			 return true;
    	    			  }
    	    		 else {           //�����ǵ�һ�η�ֵ����Ҫ����һ�η�ֵ������ʱ����бȽϣ������ߵĲ�ֵ��200ms~2000ms֮���� �Ʋ�������ʹ��һ��1*2�������ʾ������һ�κ���һ�ε�ʱ��ģ�
    	    			 
    	    		  
    	    		 
    	    		 if(times[(position1+1)%3]-temptime>=200&&times[(position1+1)%3]-temptime<=2000)
    	    		 { temptime=times[(position1+1)%3];
    	    		 datas[position1] = variable;
    	    		 times[position1]=time;
    	             position1++;
    	    			 return true;
    	    		 } 
    	    		
    	    		 datas[position1] = variable;
    	    		 times[position1]=time;
    	             position1++;
     	    		return false;         //ʱ�䲻���� �����Ʋ���
    	    		 }
     }else datas[position1] = variable;
    	    	 times[position1]=time;
                 position1++;
                 return false;                //��ֵ������ ���Ʋ���
    	    	 
    	     
    	     }
    	     else datas[position1] = variable; //���Ǽ�Сֵ�㲻�Ʋ�
    	     times[position1]=time;//���Ǽ�Сֵ�㲻�Ʋ�
             position1++;
             return false;
    	     }
    	      else {
    	    	  flag3=0;flag2=0;
    	      datas[position1] = variable; //���Ǽ�Сֵ�㲻�Ʋ�
     	     times[position1]=time;//���Ǽ�Сֵ�㲻�Ʋ�
              position1++;
              return false;
    	      
    	      }
    	}
    	}
    
}